import axios from "axios"
import Vue from "vue"
import { ElLoading } from 'element-plus'
import { ElMessage } from 'element-plus'


//使用create创建实例,公共属性
const loadingObj = null
const Service =axios.create({
    timeout: 8000,
    baseURL: "http://localhost:8080/",
    withCredentials: true,
    headers: {
        "Content-type":"application/json;charset=utf-8"
    }
})
//请求拦截，增加loading，对请求做统一处理
Service.interceptors.request.use(config=>{
//     loadingObj=ElLoading.service({
//         lock: true,
//         text: 'Loading正在加载中',
//         background: 'rgba(0, 0, 0, 0.7)',
// })
let token = localStorage.getItem("token")
config.headers.Authorization = "yyyyy"+token
return config
},
error => {return Promise.reject(error)}
)

//响应拦截，对返回值做统一处理
Service.interceptors.response.use(response=>{
    
    return response.data
},error=>{ 
    
    ElMessage({
        message:"服务器错误",
        type:"error",
        duration:2000
    })
})

export default Service;